* This is an unpublished work protected by Website Pros, Inc.
* as a trade secret, and is not to be used or disclosed except as
* expressly provided in a written license agreement executed by
* you and Website Pros, Inc.
*
* <copyright@websitepros.com>
*
* NOTES
* JavaScript code.
*
*****/
if (!IS.isModuleInitialized("IS.NOF.UTIL.Validator"))
{
/****h* NOF_JavaScript_Library/NOF.UTIL.Validator
*
* NAME
* NOF.UTIL.Validator
*
* DESCRIPTION
* Input validator class.
*
* External dependencies:
****/
/**
* Constructor
*/
function NOF_Validator () {
this.__proto__ = NOF_Validator.prototype;
this.isRequired = false;
this.isAlphaNum = false;
this.isFileName = false;
this.isAttributeValue = false;
this.isAlhaNumNoSpace = false;
this.isEmail = false;
this.isLetter = false;
this.isAscii = false;
this.isDigit = false;
this.isDouble = false;
this.isUSDouble = false;
this.isPercentage = false;
this.isAnyChars = false;
this.minLength = 0;
this.maxLength = "unlimited";
this.lengthOverLimit = false;
this.isLengthRequired = true;
this.invalidChar = '';
}
function NOF_Validator_ProtoBuilder() {
var method = NOF_Validator.prototype;
method.setIsRequired = function setIsRequired(isFieldNeeded) {
this.isRequired = isFieldNeeded;
}
method.setIsAlphaNum = function setIsAlphaNum (isAlpha) {
if (isAlpha) this.disableAll();
this.isAlphaNum = isAlpha;
}
method.setIsFileName = function setIsFileName (isFileName) {
if (isFileName) this.disableAll();
this.isFileName = isFileName;
}
method.setIsAttributeValue = function setIsAttributeValue (isAttributeValue) {
if (isAttributeValue) this.disableAll();
this.isAttributeValue = isAttributeValue;
}
method.setIsAlphaNumNoSpace = function setIsAlphaNumNoSpace (isAlphaNoSpace) {
if (isAlphaNoSpace) this.disableAll();
this.isAlphaNumNoSpace = isAlphaNoSpace;
}
method.setIsAnyChars = function setIsAnyChars (isAny) {
if (isAny) this.disableAll();
this.isAnyChars = isAny;
}
method.setIsEmail = function setIsEmail (isEmail) {
if (isEmail) this.disableAll();
this.isEmail = isEmail;
}
method.setIsAscii = function setIsAscii (isAscii) {
if (isAscii) this.disableAll();
this.isAscii = isAscii;
}
method.setIsLetter = function setIsLetter (isLttr) {
if (isLttr) this.disableAll();
this.isLetter = isLttr;
}
method.setIsDigit = function setIsDigit (isInt) {
if (isInt) this.disableAll();
this.isDigit = isInt;
}
method.setIsDouble = function setIsDouble (isDbl) {
if (isDbl) this.disableAll();
this.isDouble = isDbl;
}
method.setIsUSDouble = function setIsUSDouble (isDbl) {
if (isDbl) this.disableAll();
this.isUSDouble = isDbl;
}
method.setIsPercentage = function setIsPercentage (isPrcnt) {
if (isPrcnt) this.disableAll();
this.isPercentage = isPrcnt;
}
method.setMinLength = function setMinLength (minValue) {
if (this.maxLength < minValue) {
this.minLength = this.maxLength;
this.maxLength = minValue;
}
else
this.minLength = minValue;
}
method.setMaxLength = function setMaxLength (maxValue) {
if (this.minLength > maxValue) {
this.maxLength = this.minLength;
this.minLength = maxValue;
}
else
this.maxLength = maxValue;
}
method.disableAll = function disableAll () {
this.isDouble = false;
this.isUSDouble = false;
this.isAlphaNum = false;
this.isFileName = false;
this.isAttributeValue = false;
this.isAlhaNumNoSpace = false;
this.isEmail = false;
this.isLetter = false;
this.isDigit = false;
this.isPercentage = false;
this.isAnyChars = false;
}
method.isValid = function isValid(str, re) {
if (re != null && !re.test(str)){
return false;
}
return true;
}
method.isEmptyString = function isEmptyString(str) {
var emptyRe = /\S+/;
if (!emptyRe.test(str))
return true;
return false;
}
method.isValidLength = function isValidLength (str) {
if (this.isLengthRequired) {
if (str.length < this.minLength) {
this.lengthOverLimit = true;
return false;
}
if (this.maxLength != "unlimited" && str.length > this.maxLength) {
this.lengthOverLimit = true;
return false;
}
}
return true;
}
method.isValidDoubleLength = function isValidDoubleLength (str) {
if (this.isLengthRequired) {
var index = str.indexOf (".");
if (index == -1)
index = str.indexOf (",");
if (index == -1)
index = str.length;
var w = str.substring (0,index);
var d = str.substring (index+1);
if (d.length > this.minLength)
return false;
if (this.maxLength != "unlimited" && w.length > this.maxLength)
return false;
}
return true;
}
method.isValidAlphaNum = function isValidAlphaNum (str) {
var re = new RegExp ("[^0-9a-zA-Z-. \ufeff\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d9\u00da\u00db\u00dc\u00dd\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff\u00df]",""); //└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓┘┌█▄▌αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷∙·√ⁿ²■ ▀
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidAlphaNumNoSpace = function isValidAlphaNumNoSpace (str) {
var re = new RegExp ("[^0-9a-zA-Z-.\ufeff\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d9\u00da\u00db\u00dc\u00dd\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff\u00df]",""); //└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓┘┌█▄▌αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷∙·√ⁿ²■ ▀
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidFileName = function isValidFileName(str) {
var re = /[\\\/:*?\"<>|]/;
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidPhoneNumber = function (str) {
var re = /^(\+?\d{1,2})?([\s\-])?((\(\d+\))|(\d+))([\d\s.\-]*)$/; // General: +<country code> (area) phone number
if (!this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidAttributeValue = function isValidAttributeValue(str) {
var re = /["]/;
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidAnyChars = function isValidAnyChars (str) {
return this.isValidLength(str);
}
method.isValidAscii = function isValidAscii (str) {
var idx = str.length;
for (i=0; i<idx; i++)
if (str.charCodeAt(i) > 128) {
this.invalidChar = str.charAt(i);
return false;
}
return this.isValidLength(str);
}
method.isValidEmail = function isValidEmail (str, isInputValidation) {
var re = /[^0-9a-zA-Z-._@]/;
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
if (isInputValidation) {
re = /^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!this.isValid (str, re)) {
return false;
}
}
var mail = str.split('@');
if (mail[0].length > 64)
return false;
if (mail[1] && mail[1].length > 256)
return false;
return true;
}
method.isValidLetter = function isValidLetter (str) {
//var re = /[^a-zA-Z]/;
var re = /[^a-zA-Z\ufeff\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d9\u00da\u00db\u00dc\u00dd\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff\u00df]/;
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
return this.isValidLength(str);
}
method.isValidDouble = function isValidDouble (str, isInputValidation, isUSDouble) {
//debugger;
var re = /[^0-9.,]/;
if (isUSDouble)
re = /[^0-9.]/;
if (this.isValid (str, re)) {
this.invalidChar = RegExp.lastMatch;
return false;
}
if (isUSDouble) {
re = /.*\..*\..*/;
if (this.isValid (str, re))
return false;
}
if (isInputValidation) {
re = /[0-9]$/;
if (!this.isValid (str, re))
return false;
}
return this.isValidDoubleLength(str);
}
method.isValidUSDouble = function isValidUSDouble (str, isInputValidation) {